<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>排班表</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
  <script type="text/javascript">
  $(function(){
	  	
  });
	function toSave(){
	    $("#save").hide();
		var data=$("#timeTable").serialize();
		$.ajax({
			url: "<%=path%>/tmblWorktimeController.do?doUpdateTable",
			type:"post",
			dataType:"json",
			data:data,
			success: function(data){
				if(data.success){
					var div1 = document.getElementById("box");
					 var all = div1.getElementsByTagName('input');
				
					 $("input").each(function(i){
						$(this).removeAttr("onclick");
					 })
					 $.dialog({
							id:'b',
							title:'提示',
							content: data.msg,
							lock : true,
							zIndex: getzIndex(),
							width:300,
							height:60
						});
					
				}else{
					$.dialog({
						id:'b',
						title:'提示',
						content: data.msg,
						lock : true,
						zIndex: getzIndex(),
						width:300,
						height:60
					});
					$("#save").show();
				}
				
				
			}
		});
	}
	function excel(){
		var pid=$("#pid").val();
		window.location = "<%=path%>/tmblWorktimeParentController.do?excelTable&id=" + pid;
	}
	
	var id=0;
	var wid=0;
	var pid=0;
	var wd=0;
	function selectAppUser(ids){
		$.dialog.setting.zIndex = getzIndex(true); 
		id=ids;
		$.dialog({content: 'url:tmblWorktimeParentController.do?goSelectAppUser', 
				zIndex: 2100, title: '用户列表', lock: true, width: '500px', 
				height: '600px', opacity: 0.4, 
		button: [
		   {name: '确定', callback:callbackDepartmentSelect, focus: true},
		   {name: '取消', callback: function (){}}
	   ]}).zindex();
	}
	
	function callbackDepartmentSelect(){
		
		 var iframe = this.iframe.contentWindow;
	    var rowsData = iframe.$('#selectAppUser').datagrid('getSelections');
   		 if (!rowsData || rowsData.length==0) {
	        tip('<t:mutiLang langKey="common.please.select.edit.item"/>');
	        return;
   		 }
	    var cde = rowsData[0].empCde;
	    var name = rowsData[0].empName;
	    //检查用户是否重复
	    <%-- $.ajax({
			url: "<%=path%>/tmblWorktimeParentController.do?checkName",
			type:"post",
			dataType:"json",
			data:{
				wid:wid,
				pid:pid,
				wd:wd,
				empCde:cde
			},
			success: function(data){
				if(data.success){
					$("#cde"+id).val(cde);
				    $("#"+id).val(name);
				    $("#"+id).blur(); 
				}else{
					$.dialog({
						id:'b',
						title:'提示',
						content: '用户已经重复',
						lock : true,
						zIndex: getzIndex(),
						width:300,
						height:60
					});
				}
				
			}
		}); --%>
	    $("#cde"+id).val(cde);
	    $("#"+id).val(name);
	    $("#"+id).blur(); 
	}
	var time =0;
	function add(i,workplace,workPlaceId,parentId,workdate) {
		if(time=='0'){
			time=$("#newNum").val();
		}
		
		var s = i.toString();
		/* var p = 'bok1'+s;
		$("#"+p).show(); */
		var q=s+"a";
		var times=time.toString();
	var mess="<label id='t"+q+times+"'>"+
            "<input type=\"hidden\" name=\"addWtList["+time+"].workplace\" value=\""+workplace+"\"/>"+
            "<input type=\"hidden\" name=\"addWtList["+time+"].workPlaceId\" value=\""+workPlaceId+"\"/>"+
             "<input type=\"hidden\" name=\"addWtList["+time+"].parentId\" value=\""+parentId+"\"/>"+
             "<input type=\"hidden\" name=\"addWtList["+time+"].workdate\"  value=\""+workdate+"\"/>"+
        	"<input type=\"hidden\" id=\"cde"+q+time+"\" name=\"addWtList["+time+"].empcdoe\" />"+
        	"<input type=\"text\" id=\""+q+time+"\" onclick=\"selectAppUser('"+q+time+"')\" name=\"addWtList["+time+"].empname\" style=\"height: 25px; font-size:16px;\" />"+
        	"<input style=\"float: right; width: 6px;height: 20px;\" type=\"button\" value=\"-\" onclick=\"left('t"+q+times+"')\">"+
        	"</label>"
		$("#a"+i).append(mess); 
        time=parseInt(time);
		time =time+1;
	}
	function left(i){
		var s = i.toString();
		$("#"+s).html(""); 
		$("#"+s).hide();
	}
	
  </script>
  <style type="text/css">
  	.tableA{
  	border-collapse:collapse;
  	
  	}
  	
  	input{
		width: 55px;
		height: 19px;
	}
	td{
		font-size:15px;
		margin-left: 10px;
		text-align: center;
		border: 1px solid black;
	}
	tr{
		
		height: 50px;
	}
  </style>
 </head>
<body style="overflow:scroll;">
	<form id="timeTable"  action="" >
	
		<table id="box" class="tableA" border="1" cellpadding ="5" cellspacing="10" style="width: 500px;height: 400px; ">
			<tr>
			<td > <% for(int i=0;i<29;i++){ %>&nbsp;<%} %></td>	
				<c:forEach items="${daysList }" var="day">
				<td width="100">${day}</td>
				</c:forEach>
			</tr>
			
			<%int i=0; %>
			<%int j=0; %>
<c:forEach items="${wdataList }" var="wd">
<tr >
		<td style="width:20%;">${wd.workPlaceName }</td>
				<c:forEach items="${wd.wtime}" var="data">
				<td>
	            	<input type="hidden" name="wtList[<%=i %>].id" value="${data.id }"/>
	                <input type="hidden" name="wtList[<%=i %>].workplace" value="${data.workplace }"/>
	                <input type="hidden" name="wtList[<%=i %>].workPlaceId" value="${data.workPlaceId }"/>
	                 <input type="hidden" name="wtList[<%=i %>].parentId" value="${data.parentId }"/>
	                 <input type="hidden" name="wtList[<%=i %>].workdate"  value="${data.workdate }"/>
	            	
	            	<input type="hidden" id="cde<%=i %>" name="wtList[<%=i %>].empcdoe" value="${data.empcdoe }"/>
	            	<input type="text" id="<%=i %>" onclick="selectAppUser(<%=i %>)" name="wtList[<%=i %>].empname" style="height: 25px; font-size:16px;" value="${data.empname }"/>
	             	
	             	
	             	<!-- 获取新增的排班信息 -->
	              <c:forEach items="${newdataList}" var="newdata">
	              	<c:if test="${data.workPlaceId==newdata.workPlaceId && data.workdate==newdata.workdate }">
	              	<input type="hidden" name="addWtList[<%=j %>].id" value="${newdata.id }"/>
	                <input type="hidden" name="addWtList[<%=j %>].workplace" value="${newdata.workplace }"/>
	                <input type="hidden" name="addWtList[<%=j %>].workPlaceId" value="${newdata.workPlaceId }"/>
	                 <input type="hidden" name="addWtList[<%=j %>].parentId" value="${newdata.parentId }"/>
	                 <input type="hidden" name="addWtList[<%=j %>].workdate"  value="${newdata.workdate }"/>
	            	
	            	<input type="hidden" id="cde<%=j %>add" name="addWtList[<%=j %>].empcdoe" value="${newdata.empcdoe }"/>
	            	<input type="text" id="<%=j %>add" onclick="selectAppUser('<%=j %>add')" name="addWtList[<%=j %>].empname" style="height: 25px; font-size:16px;" value="${newdata.empname }"/>
	             	
	              	 <%j=j+1; %>
	              	</c:if>
	              	
	              </c:forEach>
	              
	              <label id="a<%=i %>" style="margin-top: 5px">	 </label> 
	              
	              
	             <%-- <div id="bok1<%=i %>" style="display:none;">
	             	<input type="hidden" name="addWtList[<%=i %>].id" value="${data.id }"/>
	                <input type="hidden" name="addWtList[<%=i %>].workplace" value="${data.workplace }"/>
	                <input type="hidden" name="addWtList[<%=i %>].workPlaceId" value="${data.workPlaceId }"/>
	                 <input type="hidden" name="addWtList[<%=i %>].parentId" value="${data.parentId }"/>
	                 <input type="hidden" name="addWtList[<%=i %>].workdate"  value="${data.workdate }"/>
	            	
	            	<input type="hidden" id="cde<%=i %>a" name="addWtList[<%=i %>].empcdoe" value=""/>
	            	<input type="text" id="<%=i %>a" onclick="selectAppUser('<%=i %>a')" name="addWtList[<%=i %>].empname" style="height: 25px; font-size:16px;" value=""/>
	             	
	             </div> --%>
	             	<input type="button" value="+" onclick="add(<%=i %>,'${data.workplace }','${data.workPlaceId }','${data.parentId }','${data.workdate }')"> 
	             	 
	             </td>
	             
	            
	             	
	             <%i=i+1; %>
	             </c:forEach>
             
	
</tr>
</c:forEach>	
	
		</table>
	</form>
	<input id="pid" type="hidden" value="${pId}">
	<div style="margin-top: 6px;"><input id="save" type="button" style="width:70px;height: 30px; font-size: 17px;" value="保存" onclick="toSave()"/></div>

	<input id="newNum" value="<%=j %>" type="hidden">
	
</body>
</html>